package com.jpxx.mina;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TCPClientHandler extends IoHandlerAdapter {
	
    @Override
	public void messageReceived(IoSession session, Object message) throws Exception {
    	  String str = message.toString();
          System.out.println("Client    ------message received is [" + str + "]");
          if (str.endsWith("quit")) {
        	  System.out.println("quit");
              session.close(true);
              
              return;
          }
         // session.getService().dispose();
	}

	private final static Logger LOGGER = LoggerFactory.getLogger(TCPClientHandler.class);
    private final String values;

    public TCPClientHandler(String values) {
        this.values = values;
    }

    @Override
    public void sessionOpened(IoSession session) {
        session.write(values);
    }
}
